package info.hengha.blue.dao;

import info.hengha.blue.model.Alias;
import info.hengha.utils.HibernateUtil;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class AliasDao {

    private SessionFactory sessionFactory;

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    public void add(Alias alias) {
        if (alias != null) {
            //HibernateUtil util = new HibernateUtil();
            Session session = sessionFactory.getCurrentSession();
            session.getTransaction().begin();
            /*
             category.setVirtualPath("");
             session.save(category);
             session.flush();
             if ("category".equals(category.getType())) {
             if (category.getParentId() > 0) {
             Query q = session.createQuery("from Category where id=?");
             q.setInteger(1, category.getParentId());
             Category parent = (Category) q.uniqueResult();
             category.setVirtualPath(parent.getVirtualPath() + "-" + category.getId());
             } else {
             category.setVirtualPath(String.valueOf(category.getId()));
             }
             }
             */
            session.getTransaction().commit();
            session.close();
        }
    }

    public List<Alias> getAliasesByCategoryId(int categorId) {
        throw new UnsupportedOperationException();
    }
}
